package com.example;

import android.os.Environment;
import com.example.calladapter.CustomCallAdapterFactory;
import com.okhttp.cache.Cache;
import com.okhttp.retrofit.RetrofitClient;
import com.okhttp.retrofit.RetrofitClient.Config;
import java.io.File;
import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import retrofit2.CallAdapter;
import retrofit2.Retrofit;

/**
 * @author GYL
 * @dateTime 2020/4/17-11:20
 * @description 应用主程序
 */
public class App extends android.app.Application {
  
  private static App instance;
  
  public synchronized static App getInstance() {
    return instance;
  }
  
  @Override
  public void onCreate() {
    super.onCreate();
    instance=this;
    
    File file= new File(Environment.getExternalStorageDirectory(),"/cache");
    Cache.getInstance().init(this).create(file,Cache.MAX_SIZE);
    Cache.getInstance().init(this).enableEncryption(true);
    //
    RetrofitClient.Config config = new Config()
                                     .withHostUrl("http://192.168.10.78:3001/")
                                      .withMock(true)
                                     .addCallAdapterFactory(CustomCallAdapterFactory.create())
                                     .withDebug(true);
    RetrofitClient.getInstance().setRetrofitConfig(config);
  }
}